package org.dromara.system.controller.xiaofu;


import org.dromara.common.core.domain.R;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.system.domain.XfReviewRating;
import org.dromara.system.domain.query.XfReviewRatingQuery;
import org.dromara.system.domain.vo.XfReviewRatingVo;
import org.dromara.system.service.IXfReviewRatingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/xiaofu/reviewRating")
public class XfReviewRatingController extends BaseController {

    @Autowired
    private IXfReviewRatingService xfReviewRatingService;

    @GetMapping("/list")
    public TableDataInfo<XfReviewRatingVo> list(XfReviewRatingQuery query){
        return xfReviewRatingService.selectPageXfReviewRatingList(query);
    }

    @GetMapping("/review/{reviewId}")
    public TableDataInfo<XfReviewRatingVo> getByReviewId(@PathVariable Long reviewId){
        XfReviewRatingQuery query = new XfReviewRatingQuery();
        query.setReviewId(reviewId);
        return xfReviewRatingService.selectPageXfReviewRatingList(query);
    }

    @GetMapping("/{id}")
    public R<XfReviewRatingVo> getDetail(@PathVariable Long id){
        XfReviewRatingVo xfReviewRatingVo = xfReviewRatingService.selectXfReviewRatingById(id);
        return R.ok(xfReviewRatingVo);
    }

    @PostMapping
    public R<Void> add(@RequestBody XfReviewRating reviewRating){
        // 确保reviewId不为空
        if (reviewRating.getReviewId() == null) {
            return R.fail("评价ID不能为空");
        }
        // 确保dimensionId不为空
        if (reviewRating.getDimensionId() == null) {
            return R.fail("维度ID不能为空");
        }
        // 确保score不为空
        if (reviewRating.getScore() == null) {
            return R.fail("评分不能为空");
        }
        boolean result = xfReviewRatingService.insertXfReviewRating(reviewRating);
        return toAjax(result);
    }

}
